%-------------------------------------------------------------------------;
% Figure 2: Cumulative Returns;
%-------------------------------------------------------------------------;

clear;
clc;
close all;

%-------------------;
% Import data;
%-------------------;

filename='Main_data_1996_2022';
[data,txt,raw]=xlsread(filename);

dates=txt(2:end,1);

%Index data;
SP_500=data(:,1);         %SP 500 index price level;
Div_m=data(:,2);            %Monthly index dividends;
Div_a=data(:,3);            %Annual index dividends;
SP_ret=data(2:end,4);       %Monthly return on SP 500 index;

%Dividend strip data;
Div_strip_12=data(:,5);     %Price of 12-month dividend strip;
Div_strip_ret=data(2:end,6);%Monthly return on dividend strip strategy;

%Indicated dividends;
Ind_div=data(1:end,7);  

%Bond returns;
Bond_2y=data(2:end,8);      %Monthly return on 2-year Treasury bond;
Bond_10y=data(2:end,9);     %Monthly return on 10-year Treasury bond;

%Fama-French data;
Mkt_Rf=data(2:end,10);      %Market factor;
Rf=data(2:end,11);          %Risk-free rate;

%Define dividend-to-price ratios;
DP_sp=Div_a./SP_500;
DP_strip=Div_a./Div_strip_12;

%Define indicated dividend growthh;
Ind_dg=(Ind_div./Div_a)-1;     

%Take logarithms of all the main variables;
ret_sp=log(SP_ret+1);
ret_strip=log(Div_strip_ret+1);

bond_2y=log(Bond_2y+1);  
bond_10y=log(Bond_10y+1);

mkt_rf=log(Mkt_Rf+1);
rf=log(Rf+1);

dp_sp=log(DP_sp);
dp_strip=log(DP_strip);

ind_dg=log(Ind_dg+1);

%------------------------------------;
%Figure 2; Cumulative returns;
%------------------------------------;

%------------------------------------;
%Panel A: Raw returns;
%------------------------------------;

ret_Strip=Div_strip_ret;    %Take raw strip return;
ret_SP=SP_ret;              %Take raw SP return;

ret_cum_Strip=ones(size(data,1),1);
ret_cum_SP=ones(size(data,1),1);

for i=2:length(data)
    ret_cum_Strip(i)=ret_cum_Strip(i-1)*(1+ret_Strip(i-1));
    ret_cum_SP(i)=ret_cum_SP(i-1)*(1+ret_SP(i-1));
end

figure(1)
plot(ret_cum_Strip,'-','LineWidth',1)
hold on;
plot(ret_cum_SP,':','LineWidth',1)
hold on;
set(gca, 'XTick', 12:48:length(dates));
set(gca, 'XTickLabel', dates(12:48:length(dates)));
legend('Dividend strip','Market');
axis([1 length(data(:,1)) 0 13]);
ylabel('Investment in $')
set(gca,'FontSize',8)

%------------------------------------;
%Panel B: In excess of the Rf;
%------------------------------------;

%Take excess returns (in logs) and transform them into raw excess returns;

ret_strip_ex=ret_strip-rf;
ret_sp_ex=ret_sp-rf; 

ret_Strip=exp(ret_strip_ex)-1;
ret_SP=exp(ret_sp_ex)-1;

ret_cum_Strip=ones(size(data,1),1);
ret_cum_SP=ones(size(data,1),1);

for i=2:length(data)
    ret_cum_Strip(i)=ret_cum_Strip(i-1)*(1+ret_Strip(i-1));
    ret_cum_SP(i)=ret_cum_SP(i-1)*(1+ret_SP(i-1));
end

figure(2)
plot(ret_cum_Strip,'-','LineWidth',1)
hold on;
plot(ret_cum_SP,':','LineWidth',1)
hold on;
set(gca, 'XTick', 12:48:length(dates));
set(gca, 'XTickLabel', dates(12:48:length(dates)));
legend('Dividend strip - rf','Market - rf');
axis([1 length(data(:,1)) 0 13]);
ylabel('Investment in $')
set(gca,'FontSize',8)

%----------------------------------------;
%Panel C: In excess of Treasury returns;
%----------------------------------------;

%Take excess returns (in logs) and transform them into raw excess returns;

ret_strip_ex=ret_strip-bond_2y;
ret_sp_ex=ret_sp-bond_10y; 

ret_Strip=exp(ret_strip_ex)-1;
ret_SP=exp(ret_sp_ex)-1;

ret_cum_Strip=ones(size(data,1),1);
ret_cum_SP=ones(size(data,1),1);

for i=2:length(data)
    ret_cum_Strip(i)=ret_cum_Strip(i-1)*(1+ret_Strip(i-1));
    ret_cum_SP(i)=ret_cum_SP(i-1)*(1+ret_SP(i-1));
end

figure(3)
plot(ret_cum_Strip,'-','LineWidth',1)
hold on;
plot(ret_cum_SP,':','LineWidth',1)
hold on;
set(gca, 'XTick', 12:48:length(dates));
set(gca, 'XTickLabel', dates(12:48:length(dates)));
legend('Dividend strip - Treasury 2y','Market - Treasury 10y');
axis([1 length(data(:,1)) 0 13]);
ylabel('Investment in $')
set(gca,'FontSize',8)


